<template>
    <div>
        <div>
            车型：
            <Input v-model="searchData.title" style="width: 200px"></Input>

            <Button @click="search" type="primary" icon="ios-search" style="margin-left: 10px;">搜索</Button>
            <Button @click="reset" type="warning" icon="ios-refresh" style="margin-left: 10px;">刷新</Button>
            <Button slot="extra" @click="edit(false)" type="success" style="margin-left: 10px;">添加</Button>
        </div>
        <br>
        <Table :columns="columns" :data="list" @on-sort-change="customSort" :highlight-row="true" max-height="800" border
            stripe>
            <template slot-scope="{ row , index}" slot="typeSlot">
                <div v-html="row.content"></div>
            </template>
            <template slot-scope="{ row , index}" slot="contextSlot">
                <div style="height: 200px;width: 100px;"><span v-html="row.context"></span></div>

            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <Tooltip content="编辑" style="margin-left: 10px;" placement="top">
                    <Icon type="ios-create" size="24" color="#2d8cf0" style="cursor: pointer;" @click="edit(row)" />
                </Tooltip>
                <Tooltip content="删除" style="margin-left: 10px;" placement="top">
                    <Icon type="md-trash" size="24" color="#ed4014" style="cursor: pointer;" @click.stop="del(row.id)" />
                </Tooltip>
            </template>
        </Table>
        <br>

        <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize" :current="searchData.page">
        </Paginate>


        <Modal title="添加" width="30" v-model="showAdd" @on-ok="addQuestion">
            <Form ref="formValidate" :model="formItem" :label-width="100">
                <FormItem label="车型">
                    <Input v-model="formItem.title" placeholder=""></Input>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
import Paginate from "_c/paginate";

export default {
    name: "configShape",
    components: {
        Paginate
    },
    data() {
        return {
            searchData: {
                page: 1,
                limit: 10
            },
            // 列表
            columns: [
                {
                    title: 'ID',
                    key: 'id',
                    align: 'center',
                },
                {
                    title: '车型',
                    key: 'title',
                    align: 'center',
                },
                {
                    title: '创建时间',
                    key: 'create_time',
                    align: 'center',
                },
                {
                    title: '操作',
                    slot: 'makeSlot',
                    align: 'center',
                },
            ],
            // 数据
            list: [],
            total: 0,
            formItem: {},
            showAdd: false,
        }
    },
    methods: {
        // 查询管理员信息
        getList() {
            this.$axios('/admin/verify/shape/getList', this.searchData).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        search() {
            this.searchData.page = 1;
            this.getList();
        },
        reset() {
            this.searchData = {
                page: 1,
                limit: 10,
            };
            this.getList();
        },
        changePage(page) {
            this.searchData.page = page;
            this.getList();
        },
        changeSize(size) {
            this.searchData.limit = size;
            this.getList();
        },
        customSort(column, key, order) {
            this.searchData.order_by = column.key;
            this.searchData.sort = column.order;
            this.getList();
        },
        addQuestion() {
            this.$axios('/admin/verify/shape/save', this.formItem).then(res => {
                this.$Message.success('保存成功');
                this.formItem = {};
                this.showAdd = false;
                this.getList();
            });

        },
        edit(row) {
            if (row) {
                this.formItem.id = row.id;
                this.formItem.title = row.title + '';
                this.formItem.content = row.content;
            } else {
                this.formItem = {
                    id: 0,
                    title: '',
                    content: '',
                }
            }
            this.showAdd = true;
        },
        del(id) {
            this.$axios('/admin/verify/shape/del', { id: id }).then(res => {
                this.$Message.success('删除成功');
                this.getList();
            });
        },

    },
    created() {
        this.getList();
    }
}
</script>
